<?php
class AppRoveUser extends Controller {
	function AppRoveUser() {
		parent::Controller();
		//$this->load->library('email');
		$this->load->helper("url");
		$this->data["base"] = $this->config->item('base_url');
		$this->load->model('Userapprovemodel');
		$this->load->model('TransLog');
		$this->load->database();	
                session_start();
	}
	function index() {
		if(isset($_SESSION['sys_admin']) and isset($_SESSION['name'])) {
			$this->data['title']='User Approved';
			$this->formAprove();
			$this->show_aktif();
			} else {
			
			$this->load->view('layout/head', $this->data);
			$this->load->view('layout/body', $this->data);
			$this->load->view('layout/login-index', $this->data);
			$this->load->view('layout/footer', $this->data);
		}
	}
	var $limit=10;
	function formAprove($offset=0) {
			$this->show_aktif();
			$this->data['title']='User Approved';
			$uri_segment=4;
			$offset=$this->uri->segment($uri_segment);
			
			/*---------------------------------------------------------------------------
			User Non Aktif*/
			$status =0;
			$this->data['as'] =$this->Userapprovemodel->show_non_aktif($offset); 
			$aprove = $this->Userapprovemodel->show_non_aktif($offset)->result();
			$num_rows = $this->Userapprovemodel->numrows();
			if($num_rows > 0) {
			$config['base_url'] = site_url('userAprove/appRoveUser/formAprove');
			$config['total_rows'] = $num_rows;
			$config['per_page'] = $this->limit;
			$config['uri_segment'] = $uri_segment;
			$this->pagination->initialize($config);
			$this->data['pagination'] = $this->pagination->create_links();

			
		//set template table untuk efek selang-sling tiap bariS
			$tmpl = array('table_open' =>'<table border="0" cellpadding="0" cellspacing="0" width="760">','row_alt_start' =>'<tr class="tb-jd">','row_alt_end' =>'</tr>');
			$this->table->set_template($tmpl);
			$this->table->set_empty("&nbsp;");
			$this->table->set_heading('No','Name','Email','Dept Name','Status','Action');
		
			$this->data['i'] = 0 + $offset;
			$i =0 + $offset;
			$this->data['stat'] ="Non";
			foreach($aprove as $as) {
			$stat = "Non";
				$this->table->add_row(++$i,$as->name,$as->email,$as->dept_name,$stat,anchor('userAprove/appRoveUser/update_aktif/'.$as->user_id,'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;',array('class'=>'nonaktif','onclick'=>"return confirm('Anda yakin akan mengaktifkan user ini ..?')")));
			}
			}
			$this->data['table'] = $this->table->generate();
			
			$this->load->vars($this->data);
			$this->load->view('layout/head');
			$this->load->view('layout/body');
			$this->load->view('layout/slice-atas');
			$this->load->view('useraprove/view_user_approve');
			$this->load->view('layout/slice_bawah');
			
			
			

			
	}
	var $limits=10;
	function show_aktif($offSet=0) {
		
			$this->data['h2_title'] = 'User Aktif';
			//$offset = 0;
		
			//$this->output->enable_profiler(true);
			//offset
			$uri_segments = 4;
			$offSet = $this->uri->segment($uri_segments);
			//die($offset);
			$num_row = $this->Userapprovemodel->numrows_2();
			if($num_row > 0) {
			
			$configs['base_url'] = site_url('userAprove/appRoveUser/formAprove');
			$configs['total_rows'] = $num_row;
			//$configs['per_page'] = $this->limits;
			$configs['uri_segment'] = $uri_segments;
			$this->pagination->initialize($configs);
			$this->data['pagination'] = $this->pagination->create_links();
			$this->data['show'] = $this->Userapprovemodel->show_user_aktif();
			$this->data['i'] =0 + $offSet;
		}
	}
	function update_aktif($id) {
		if(getenv("HTTP_CLIENT_IP")) { 
			$ipad = getenv("HTTP_CLIENT_IP"); 
		} elseif(getenv("HTTP_X_FORWARDED_FOR")) { 
			$ipad = getenv("HTTP_X_FORWARDED_FOR"); 
		} else { 
			$ipad = getenv("REMOTE_ADDR"); 
		}
		$ipad = substr($ipad, 0,14);
		$translog_id = $this->TransLog->show_id_trans_log()->row();
		
			$this->xd = $translog_id->id + 1;
		
		
		$this->send_id =$_SESSION['name'];
		$this->tgl = date('Y-m-d H:i:s');

		
		$xp=array('status' =>('1'));
		$this->Userapprovemodel->update_aktif($id,$xp);
		$this->data['success'] = 'tidak di temukan satupun data berita utama';
		
		$insert_log = array('id' => $this->xd,
							'user_id' =>$this->send_id,
							'ticket_id' =>$this->input->post(''),
							'notes' =>('Approve New User'),
							'datetime' =>$this->tgl,
							'ip' =>$ipad);
		//insert ke table trans log
		$this->TransLog->insert_log($insert_log);
		
		redirect('userAprove/appRoveUser');
	}
	function update_non($id) {
		//insert log
		if(getenv("HTTP_CLIENT_IP")) { 
			$ipad = getenv("HTTP_CLIENT_IP"); 
		} elseif(getenv("HTTP_X_FORWARDED_FOR")) { 
			$ipad = getenv("HTTP_X_FORWARDED_FOR"); 
		} else { 
			$ipad = getenv("REMOTE_ADDR"); 
		}
		$ipad = substr($ipad, 0,14);
		$translog_id = $this->TransLog->show_id_trans_log()->row();
		
			$this->xd = $translog_id->id + 1;
		
		
		$this->send_id =$_SESSION['name'];
		$this->tgl = date('Y-m-d H:i:s');
		
		$xp=array('status' =>('0'));
		$this->Userapprovemodel->update_non($id,$xp);
		$this->data['success'] = 'tidak di temukan satupun data berita utama';
		
		$insert_log = array('id' => $this->xd,
							'user_id' =>$this->send_id,
							'ticket_id' =>$this->input->post(''),
							'notes' =>('Non Aktif User'),
							'datetime' =>$this->tgl,
							'ip' =>$ipad);
		//insert ke table trans log
		$this->TransLog->insert_log($insert_log);
		
		redirect('userAprove/appRoveUser');
	}
}
?>